package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.sugon.dao.DevAmPlanDao;
import com.sugon.entity.DevAmPlanEntity;
import com.sugon.modules.base.model.vo.ProcessProgressConst;
import com.sugon.service.DevAmPlanService;
import com.sugon.utils.Constant;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 设备维护计划表Service实现类
 *
 * @author sugon
 * @date 2020-08-10 10:52:35
 */
@Service("devAmMaintenancePlanService")
public class DevAmPlanServiceImpl implements DevAmPlanService {

    @Autowired
    private DevAmPlanDao devMaintenancePlanDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevAmPlanEntity queryObject(String id) {
        return devMaintenancePlanDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevAmPlanEntity> queryList(Map<String, Object> map) {
        return devMaintenancePlanDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devMaintenancePlanDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param devMaintenancePlan 实体
     * @return
     */
    @Override
    public int save(DevAmPlanEntity devMaintenancePlan) {
        devMaintenancePlan.setId(RandomUtil.randomString(32));
        devMaintenancePlan.setGmtCreate(DateUtil.date());
        devMaintenancePlan.setStatus(ProcessProgressConst.NEW);
        devMaintenancePlan.setCreateUser(ShiroUtils.getUserId());
        devMaintenancePlan.setGmtModified(devMaintenancePlan.getGmtCreate());
        devMaintenancePlan.setModifyUser(ShiroUtils.getUserId());
        // 通过产线截取
        devMaintenancePlan.setWorkshop(StrUtil.sub(devMaintenancePlan.getDevLineId(), 0, 4));
        devMaintenancePlan.setDelFlag(Constant.IS_NOT_DEL_INT);
        return devMaintenancePlanDao.save(devMaintenancePlan);
    }

    /**
     * update
     *
     * @param devMaintenancePlan 实体
     * @return
     */
    @Override
    public int update(DevAmPlanEntity devMaintenancePlan) {
        devMaintenancePlan.setModifyUser(ShiroUtils.getUserId());
        devMaintenancePlan.setGmtModified(DateUtil.date());
        return devMaintenancePlanDao.update(devMaintenancePlan);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devMaintenancePlanDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devMaintenancePlanDao.deleteBatch(ids);
    }
}
